﻿using System.Windows.Controls;
using Microsoft.VisualStudio.Shell;
using VsxTools.Attributes;
using VsxTools.UtilityTypes;

namespace VsxTools.ToolWindow
{
    public abstract class VsxToolWindowPane<TPackage, TControl> : ToolWindowPane where TPackage : Package
        where TControl : UserControl, new()
    {
        protected VsxToolWindowPane():base(null)
        {
            foreach (var attribute in GetType().GetCustomAttributes(false))
            {
                var captionAttribute = attribute as InitialCaptionAttribute;
                if (captionAttribute != null)
                {
                    Caption = StringResolver<TPackage>.Resolve(captionAttribute.Value);
                    continue;
                }
                var resIdAttribute = attribute as BitmapResourceIdAttribute;
                if (resIdAttribute != null)
                {
                    BitmapResourceID = resIdAttribute.ResourceId;
                    BitmapIndex = resIdAttribute.BitmapIndex;
                }
            }

            base.Content = new TControl();
        }
    }
}
